const router = require('koa-router')()
const { Sequelize } = require('sequelize');
const sequelize = require('../sequelize/connect')
router.get('/', async (ctx, next) => {
    ctx.body ='xxxxxxxxxx'
    console.log('xxxxxxx');
    // ctx.render('index.html')
})

router.get('/api/string', async (ctx, next) => {
  ctx.set('Access-Control-Allow-Origin', '*');
  ctx.set('Access-Control-Allow-Headers', 'Content-Type, Content-Length, Authorization, Accept, X-Requested-With , yourHeaderFeild');
  ctx.set('Access-Control-Allow-Methods', 'PUT, POST, GET, DELETE, OPTIONS');

  const artcle = sequelize.define('article', {
      title: {
        type: Sequelize.STRING
    }
  }, {
    freezeTableName: true,
    timestamps: false,
});
ctx.body = await artcle.findAll()
  // ctx.body = 'koa2 string'
})
router.get('/api/getdata', async (ctx, next) => {
   ctx.body = 'koa2 string'
})
router.get('/string', async (ctx, next) => {
   ctx.body = 'kstringstringstringstring string'
})
router.get('/json', async (ctx, next) => {
  ctx.body = {
    title: 'koa2 json'
  }
})

module.exports = router
